{% extends 'app01/base.html' %}
{% block active_case_manage %}{% endblock %}
{% block active_user %} class="active"{% endblock %}

{% block button %}
                <div class="btn-group" role="group" aria-label="Basic example">
                {% block not_in_index %}
                    <button type="button" data-toggle="modal" data-target="#createUserModal" class="btn btn-primary">新增
                    </button>
                {% endblock %}
                    <button type="button" class="btn btn-primary" disabled>编辑</button>
                    <button type="button" class="btn btn-primary" disabled>删除</button>
                    <button type="button" class="btn btn-primary" onclick="window.location.href='{% block export_url %}{% endblock %}'">导出</button>
                    <button type="button" class="btn btn-primary" onclick="window.location.reload()">刷新</button>
                </div>
            {% endblock %}
{% block sub_header %}用户管理{% endblock %}
 {% block table %}
<table class="table table-striped table-bordered table-responsive">
    <thead>
    <tr>
        <th style="width: 10px"><input type="checkbox"></th>
        <th style="width: 50px">序号</th>
        <th nowrap="nowrap">用户名</th>
        <th nowrap="nowrap">所属BU</th>
        <th nowrap="nowrap">创建时间</th>
        <th nowrap="nowrap">更新时间</th>
        <th nowrap="nowrap">备注</th>
        <th hidden="hidden">ID</th>
        <th nowrap="nowrap">操作</th>
    </tr>
    </thead>
    <tbody>
    {% for element in pages %}
        <tr style="font-size: 10px">
            <td><input type="checkbox" value="{{ element.id }}"></td>
            <td>{{ forloop.counter }}</td>
            <td>{{ element.user_name }}</td>
            <td>{{ element.user_bu }}</td>
            <td>{{ element.create_time|date:'Y-m-d H:i' }}</td>
            <td>{{ element.update_time|date:'Y-m-d H:i' }}</td>
            <td>{{ element.remarks }}</td>
            <td hidden="hidden">{{ element.id }}</td>
            <td nowrap="nowrap">
                <button data-toggle="modal" data-target=".bs-example-modal-lg"
                        onclick="showDialog(this)">修改
                </button>
                <a href="{% block delete_url %}{% url 'userManage:delete_user' element.id %}
                         {% endblock %}" id="{{ element.id }}" onclick="return deleteJob()">删除</a>
            </td>
        </tr>

    {% endfor %}
    </tbody>
</table>
{% endblock %}
{% block search %}
<form class="form-inline"
      action="{% block search_url %}{% url 'userManage:search_user' %}{% endblock search_url %}"
      id="form_Condition" method="get">
    {% csrf_token %}
    <label for="startTime">创建起始：</label>
    <input type="date" class="form-control input-sm" id="start_date" name="start_date"
            {% block search_start %}{% endblock %}
           style="width: 165px;margin-right: 5px">
    <label for="endTime">创建结束：</label>
    <input type="date" class="form-control input-sm" id="end_date" name="end_date"
           {% block search_end %}{% endblock %} style="width: 165px;margin-right: 5px">
    {% block search_condition %}<label for="case_title">所属BU：</label>
    <input class="form-control" id="user_bu" name="user_bu"
        {% block user_bu %}{% endblock %}   style="width: 120px;margin-right: 5px">{% endblock %}
    <label for="user_name">用户名：</label>
    <input class="form-control" id="user_name" name="user_name"
        {% block user_name %}{% endblock %}   style="width: 120px;margin-right: 5px">
    <br/>
    <br/>
    <div class="btn-group">
    <button type="button" class="btn btn-secondary btn-sm" id="btn_Clear" onclick="function back_to_index() {
        window.location.href='{% block back_url %}{% endblock %}';
    }
    back_to_index()">清空
    </button>
        <button type="submit" class="btn btn-info btn-sm" id="btn_Search">查询
        </button>
    </div>
</form>
{% endblock %}

{% block create_modal %}
    <div class="modal fade" id="createUserModal" tabindex="-1" role="dialog"
                         aria-labelledby="myModalLabel"
                         aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel">用户新增</h4>
                                </div>
                                <form class="form-inline" action="
                                        {% block create_case_url %}{% url 'userManage:create_user' %}{% endblock create_case_url %}"
                                      method="post">
                                    {% csrf_token %}
                                    <div class="modal-body">
                                        <label for="user_name" style="width: 70px">用户名：</label>
                                        <input name="user_name" class="form-control input_for_modal" type="text"
                                               id="user_name" required>
                                        <label for="create_time">创建时间：</label>
                                        <input name="create_time" style="width: 191px" class="form-control input_for_modal" type="datetime-local"
                                               id="create_time">
                                        <br>
                                        <label style="width: 70px" for="BU">所属BU：</label>
                                        <input name="BU" class="form-control input_for_modal" type="text"
                                               id="BU">
                                        <label style="width: 70px" for="remarks">备注：</label>
                                        <input name="remarks" style="width: 191px;" class="form-control input_for_modal" type="text"
                                               id="remarks">
                                    </div>
                                <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                        <button type="submit" class="btn btn-primary">提交</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
{% endblock %}
{% block edit_modal %}
    <div class="modal fade" id="EditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
                    </button>
                    <h4 class="modal-title" id="EditModalLabel">用户编辑</h4>
                </div>
                <form class="form-inline"
                      action="{% block edit_url %}{% url 'userManage:edit_user' %}{% endblock %}" method="post">
                    {% csrf_token %}
                    <div class="modal-body">
                        <label style="width: 70px" for="user_id">ID：</label>
                        <input name="user_id" class="form-control input_for_modal user_id" type="text"
                               id="user_id" readonly>
                        <label for="user_name" style="width: 70px;">用户名称：</label>
                        <input name="user_name" class="form-control input_for_modal user_name"
                               type="text"
                               id="user_name" required>
                        <label for="user_bu" style="width: 70px">所属BU：</label>
                        <input name="user_bu" class="form-control input_for_modal user_bu"
                               type="text" id="user_bu">
                        <label style="width: 70px" for="create_time">创建时间：</label>
                        <input name="create_time" class="form-control input_for_modal create_time"
                               type="datetime-local" style="width: 193px;" id="create_time" readonly>
                        <label style="width: 70px" for="remarks">备注：</label>
                        <input name="remarks" class="form-control input_for_modal remarks" type="text"
                               id="remarks">
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
{% endblock %}
{% block edit_script %}
    <script>
        function showDialog(obj) {
            $('#EditModal').modal('show');
            var tds = $(obj).parent().parent().find('td');
            $(".user_name").val($(tds.eq(2)).text());
            $(".user_id").val($(tds.eq(7)).text());

            $(".user_bu").val($(tds.eq(3)).text());
            var create_time = $(tds.eq(4).text()).selector
            var create_time1 = create_time.split(' ').join('T')
            $(".create_time").val(create_time1);
            $(".remarks").val($(tds.eq(6)).text());
        }

        function deleteJob() {
            return confirm("确定要删除吗?");
        }

    </script>
{% endblock %}